package com.ctgu.springstart.controller;

import com.ctgu.springstart.exception.MyException;
import com.ctgu.springstart.domain.ServerSettings;
import com.ctgu.springstart.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

@RestController
public class IndexController {

    @GetMapping("/index")
    public String Index(){
        System.out.println("热加载");
        System.out.println("热加载1");
        return "hello world hello world hello world hello!";
    }

    @GetMapping("/testJson")
    public Object testJson(){

        return new User(111, "alex",
                15, "1234567", "123@qq.com");
    }

    @RequestMapping("/testExp")
    public Object testExp(){
        int b = 1 / 0;
        return new User(111, "alex",
                15, "1234567", "123@qq.com");
    }

    @RequestMapping("/testExpPage")
    public Object testExpPage(){
//        throw  new MyException(501, "my ext异常");
        throw  new MyException();
    }

    @Autowired
    private ServerSettings serverSettings;

    @RequestMapping("/testFreeMarker")
    public ModelAndView testFreeMarker(ModelAndView modelAndView){
        modelAndView.setViewName("fm/index");
        modelAndView.addObject("setting", serverSettings);
        return modelAndView;
    }


}
